package robot;

import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.Robot;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class RobotUtil {
	public static final int GET_PIXEL_COLOR_AT_MOUSE_POS = 0;
	
	public static void main(String[] args) throws Exception {
		new RobotUtil();
	}
	
	public RobotUtil() throws Exception {
		Robot robot = new Robot();
		
		RobotController controller = new RobotController();
		controller.start();
		
		System.out.println("controller activated!");
		
		while(controller.running) {
			Thread.sleep(3000);
			
			if(controller.lastCommand == GET_PIXEL_COLOR_AT_MOUSE_POS) {
				PointerInfo a = MouseInfo.getPointerInfo();
				Point b = a.getLocation();
				int x = (int) b.getX();
				int y = (int) b.getY();
				System.out.println(x + ":" + y + " - " + robot.getPixelColor(x, y));
			}
		}
	}
	
	class RobotController extends Thread {
		public boolean running = true;
		public int lastCommand = -1;
		
		public void run() {
			try {
				BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
				
				while(running) {
					String str = br.readLine();
					if(str.matches("\\d+")) {
						lastCommand = Integer.parseInt(str);
					} else {
						running = false;
					}
				}
			}catch(Exception ex) {
				ex.printStackTrace();
			}
		}
	}
}
